package edu.zzuli.servlet;

import edu.zzuli.pojo.User;
import edu.zzuli.service.RegeistService;
import edu.zzuli.service.impl.RegeistServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created by Chen-D.W on 2017/12/26.
 */
public class CheckServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String code=request.getParameter("code");

        RegeistService regeistService=new RegeistServiceImpl();
        try {
            User user=regeistService.getUser(code);

            if(user!=null){
                user.setStatus(1);
                user.setCode(null);
                regeistService.update(user);
            }else {
                response.sendRedirect("fail.jsp");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
